import { ref } from 'vue'
import { defineStore } from 'pinia'
import { Msg_id, MesgList, Msg, Llm_id, LlmMapList } from '../utils/utils'


export const useListStore = defineStore('list', () => {
    let msgMap = new Map()
    // let curList: MesgList = { msgs: [] }

    let sparkList: MesgList = { msgs: [] }
    let yiyanList: MesgList = { msgs: [] }
    let duobaoList: MesgList = { msgs: [] }
    let glmList: MesgList = { msgs: [] }
    let qwenList: MesgList = { msgs: [] }
    let geminiList: MesgList = { msgs: [] }

    msgMap.set(LlmMapList.spark, sparkList)
    msgMap.set(LlmMapList.yiyan, yiyanList)
    msgMap.set(LlmMapList.doubao, duobaoList)
    msgMap.set(LlmMapList.glm, glmList)
    msgMap.set(LlmMapList.qwen, qwenList)
    msgMap.set(LlmMapList.gemini, geminiList)

    let llm2msgMap = new Map()
    llm2msgMap.set(Llm_id.spark, LlmMapList.spark)
    llm2msgMap.set(Llm_id.yiyan, LlmMapList.yiyan)
    llm2msgMap.set(Llm_id.doubao, LlmMapList.doubao)
    llm2msgMap.set(Llm_id.glm, LlmMapList.glm)
    llm2msgMap.set(Llm_id.qwen, LlmMapList.qwen)
    llm2msgMap.set(Llm_id.gemini, LlmMapList.gemini)

    const currentList = ref<MesgList>({msgs:[]})
    function add(input_msg: string, id: string, llm_id: Llm_id,markdown_msg:string='') {
        console.log(Msg_id.user, '    ', id)
        let val: Msg = { id: Msg_id.user, content: input_msg,orign_msg:markdown_msg }
        if (id === Msg_id.user) {
            console.log('user')
            val.id = Msg_id.user
        } else {
            console.log('bot')
            val.id = Msg_id.bot
        }
        // let llmList = msgMap.get(llm2msgMap.get(llm_id))
        // llmList.msgs.push(val)
        // console.log("llmList",llmList)
        // currentList.value.msgs = llmList.msgs
        // console.log("currentList", currentList.value.msgs);
        currentList.value.msgs.push(val)
    }
    function clear(llm_id: Llm_id) {
        let llmList: MesgList = msgMap.get(llm2msgMap.get(llm_id))

        llmList.msgs = []
        currentList.value.msgs = []
        console.log("current msg", currentList.value);

    }
    function changeCurrentList(llm: Llm_id) {
        console.log('change')
        console.log('Llm_id   ', llm)
        let llmList: MesgList = msgMap.get(llm2msgMap.get(llm))
        currentList.value.msgs = llmList.msgs
    }

    return {
        currentList,
        add,
        clear,
        changeCurrentList,
    }
})